﻿
using System.Reflection;

using Kuiper.Core.EditorAttributes;

namespace Kuiper.WinUI;

public partial class PropertyEditor : UserControl
{
	private PropertyInfo _bindingProperty = null;

	public PropertyInfo BindingProperty
	{
		get 
		{ 
			return _bindingProperty; 
		}
		set
		{
			_bindingProperty = value;
			CreateEditor(_bindingProperty);
		}
	}

	public PropertyEditor()
	{
		InitializeComponent();
	}

	private void CreateEditor(PropertyInfo property)
	{
		if (property == null) return;

		PropertyEditorLabel.Text = property.Name;

		var textboxEditorAttribute = property.GetCustomAttribute<TextboxEditorAttribute>();
		if (textboxEditorAttribute != null)
		{
			this.EditorLayoutPanel.Controls.Add(new TextBox()
			{
				Name = $"{property.Name}-TextBox",
				Location = new Point(PropertyEditorLabel.ClientRectangle.Width,0),
				Anchor = AnchorStyles.Left | AnchorStyles.Right
			});
		}
	}
}
